package index;

public class MemoryManager {

    private final int sizeMemory;
    private int usingMemory;
    private int maxOverflow = 0;

    public MemoryManager(int sizeMemory) {
        this.sizeMemory = sizeMemory;
    }

    public void clear() {
        usingMemory = 0;
    }

    public boolean isFull() {
        return sizeMemory <= usingMemory;
    }

    public void subtractInteger() {
        usingMemory+=4;
        updateOverflow();
    }

    private void updateOverflow() {
        if (usingMemory - sizeMemory > maxOverflow) {
            maxOverflow = usingMemory - sizeMemory;
        }
    }

    public void subtractIntegers(int amountInt) {
        usingMemory+=4*amountInt;
        updateOverflow();
    }

    public int size() {
        return sizeMemory;
    }

    public String buildReport() {
        return "Max. oveflow was: " + maxOverflow;
    }
}
